import { useTable, LIST_TYPE } from '@crud/index';
import { getGenCodeSearch } from '@/api/crm-agency/kgj/gen-code';

// 查询

export const codeTypeMap: Record<string, any> = { 0: '自主采购', 1: '平台赠送' };
export const exchangeTimeMap: Record<string, any> = { 0: '7日', 1: '30日', 3: '90日', 6: '180日', 12: '365日' };

// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '归属名称', prop: 'colonel_name', minWidth: 250, fixed: 'left', tooltip: true },
    { label: '归属身份', prop: 'colonel_level', minWidth: 160 },
    { label: '会员类型', prop: 'product_type', minWidth: 120 },
    { label: '兑换时长', prop: 'exchange_time', minWidth: 120, render: (s: any) => exchangeTimeMap[s.row.exchange_time] },
    { label: '兑换码状态', prop: 'code_status', minWidth: 120 },
    { label: '兑换码来源', prop: 'code_type', minWidth: 120, render: (s: any) => codeTypeMap[s.row.code_type] },
    { label: '兑换时间', prop: 'use_time', minWidth: 177, type: 'dateTime' },
    { label: '出售时间', prop: 'sold_time', minWidth: 177, type: 'dateTime' },
    { label: '用户手机号', prop: 'mobile', minWidth: 160 },
    { label: '支付金额', prop: 'total_fee', minWidth: 120 }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      genCode: ''
    },
    usePagination: false,
    columns: columns,
    getList: async ({ data: queryData }:{data: Record<string, any>}) => {
      const { genCode } = queryData;
      if (!genCode) {
        return { err: null, data: [] };
      }
      const { err, data } = await getGenCodeSearch({ genCode });
      if (err || !data) return;
      data.items = [data];
      return { err, data };
    }
  });
};
